<?php
/**
* View a list of pages relating to a tag
*
* @package folio
* @param string $tag The title of the page being shown
*/
    define("context", "folio_page_view_related");

    require("../../../includes.php");
    require_once("../view/tags.php");
    require_once("../view/page.php");

    require_once("../model/user.php");
    require_once("../view/PageArchive.php");

    global $CFG;
    global $PAGE;
    global $FOLIO_CFG;

    // Load form helper class
    $form = new folio_BaseView();

    // Retrieve passed variables (page name & user name, as well as created).
    //     These variables will be used by the menu system to build links.  See lib.php for more details.
    //    Note that the included side menu depends upon these variable names.
    $tag = folio_clean( required_param('tag') );
    $start = intval( optional_param('start',0));
    $limit = -1;
    $url = url;

    // Build the body fields
    $form = new folio_BaseView();

    // If we're an admin, then give the option to mass download pages.
    if( in_array( $_SESSION['username'], $FOLIO_CFG->page_globaldownload) ) {
        $form->Load( new folio_PageArchiveLink( -1, $tag ));
    }
	
    $form->Load(new folio_TagListViewer( $tag, $start, $limit));
	
    $body = $form->toString();

	// Create a log entry to show that we're viewing a tag list.
	folio_history_pagelog(null, 'pageofpopups_listed', $tag );
	
    // Transfer into template & write.
    templates_page_setup();

    $body = templates_draw(array(
                    'context' => 'contentholder',
                    'title' => __gettext("Related Pages"),
                    'body' => $body
                ));
    echo templates_page_draw(array(
                    __gettext('Related Pages'), $body
                ));

?>
